package DP.P1049;/*
 *   exercise
 *   DP.P1049
 *
 *   description:
 *   @data 2025/5/13     下午2:43
 *   @author 凉风
 */

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int v = sc.nextInt();
        int n = sc.nextInt();
        int[] w = new int[n];
        for (int i = 0; i < n; i++) {
            w[i] = sc.nextInt();
        }

        int[] dp = new int[v + 1];
        for (int i = 0; i < n; i++) {
            for (int j = v; j >= w[i]; j--) {
                dp[j] = Math.max(dp[j], dp[j - w[i]] + w[i]);
            }
        }
        System.out.println(v - dp[v]);
    }
}
